package main

import "fmt"

func main() {
	fmt.Println("this is amy first go test")

	a := "it's a string "
	fmt.Println(a)
	num1, num2, str := func1()
	fmt.Println(num1, num2, str)

	sum := loopTest(100)
	fmt.Println("sum= ", sum)
	ab := loopTest2()
	fmt.Println(ab)
	fmt.Println("----------")
	add_func := add(1, 2)
	fmt.Println(add_func())
	fmt.Println(add_func())
	fmt.Println(add_func())

	var procutList [10]int
	fmt.Println(len(procutList))
	fmt.Println("----------")
	procutList[8] = 9
	for index, item := range procutList {
		fmt.Println(index, item)
	}

	fmt.Println("----------")

	var num int = 10
	fmt.Println(num)
	var ptr *int
	ptr = &num
	fmt.Println(*ptr)
	*ptr = 20
	fmt.Println(*ptr)
	fmt.Println(num)

	fmt.Println("----------")

	var number = 101
	var ptr1 *int = &number
	var pptr **int = &ptr1

	fmt.Println(number)
	fmt.Println(*ptr1)
	fmt.Println(**pptr)
}

func func1() (int, int, string) {

	fmt.Println("it's a func ...")
	return 1, 2, "hello"
}

func loopTest(time int) int {
	sum := 0
	for i := 1; i < time; i++ {
		sum += i
	}
	return sum
}

func loopTest2() int {
	sum := 1
	index := 0
	for sum <= 5000 {
		sum += sum
		index++
	}
	fmt.Println(index)
	return sum
}

// 闭包使用方法
func add(x1, x2 int) func() (int, int) {
	i := 0
	return func() (int, int) {
		i++
		return i, x1 + x2
	}
}
